#ifndef _STRAWGUI_ACTION_HANDLER_H_
#define _STRAWGUI_ACTION_HANDLER_H_

#include "sControllerEvents.h"
#include "sConfig.h"
#include "sMath.h"
#include "sObserver.h"

namespace sgui
{
namespace engine
{
	class sDrawStack;
};
namespace inst
{

class sComponentInstance;
class sComponentRectInstance;

typedef enum
{
    EAEID_UNKNOWN = 0,
    EAEID_PRESS,
	EAEID_EDIT_TEXT
} EActionEventID;

struct sActionHandlerEvent
{
    virtual EActionEventID getID() const { return EAEID_UNKNOWN; }
};

#define CAST_HANDLER_EVENT(var, type) const type & var = static_cast<const type &>(event)

class sActionHandler : public obs::sSubject
{
private:
    sComponentInstance*         m_instance;
    sComponentRectInstance*     m_caller;
    math::sRectf                m_activeRect;
public:
    sComponentInstance* getInstance();
    const sComponentInstance* getInstance() const;
    sComponentRectInstance* getCaller();
    const math::sRectf& getActiveRect() const { return m_activeRect; }

	virtual void draw(engine::sDrawStack& stack) const {}
    virtual bool update(double dt);
    virtual bool isEventsLocked() = 0;
    virtual bool isUpdateLocked() = 0;

	bool notifyInstance(const sActionHandlerEvent& event);
    void release(const obs::sMouseEvent* event = NULL);

    virtual bool OnEvent(const obs::sEvent& event) = 0;

    sActionHandler(sComponentInstance* instance, sComponentRectInstance *caller);
    virtual ~sActionHandler();
};

};
};

#endif